package org.ceteca.explica.client.management;

import org.ceteca.explica.client.ClientContext;
import org.ceteca.explica.client.gui.ExplicaValueInput;
import org.ceteca.javaglade.Gui;
import org.ceteca.javaglade.handlers.GenericHandler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

public class LotOutListener extends GenericHandler implements Listener {
	private Tree w_tree;
	private Gui parentGui;
	private ExplicaValueInput valInput;
	
	public LotOutListener(Gui parentGui, Tree w_tree) {
		super();
		
		this.parentGui = parentGui;
		this.w_tree = w_tree;
		valInput = new ExplicaValueInput(ClientContext.getInstance().getLogger(), this.parentGui, "on_value_selected", this);
		valInput.build();
	}

	public void handleEvent(Event e) {
		if (e.keyCode == SWT.F2
				&& w_tree.getSelectionCount() == 1) {
			TreeItem item = w_tree.getSelection()[0];
			
			valInput.show(item.getText(2));
		}
	}
	
	public void on_value_selected(Event e) {
		if (valInput.getValue() != null) {
			TreeItem item = w_tree.getSelection()[0];
			
			item.setText(2, valInput.getValue());
		}
	}
}